from langchain.tools import tool
import re
from pydantic import BaseModel, Field
from langchain.tools import StructuredTool

class ValidateInputSchema(BaseModel):
    name: str = Field(..., description="用户姓名")
    id_number: str = Field(..., description="身份证号，18位，最后一位可为X")
    claim_amount: str = Field(..., description="理赔金额")
    description: str = Field(..., description="理赔描述")

def validate_user_claim_input_func(name: str, id_number: str, claim_amount: str, description: str) -> str:
    if not name.strip():
        return "姓名不能为空"
    if not re.fullmatch(r"\d{17}[\dX]", id_number):
        return f"身份证号格式非法：{id_number}"
    if not claim_amount.strip():
        return "金额不能为空"
    if not description.strip():
        return "理赔描述不能为空"
    return "输入有效"

validate_user_claim_input = StructuredTool.from_function(
    func=validate_user_claim_input_func,
    name="validate_user_claim_input",
    description="校验用户理赔输入：姓名不能为空，身份证号18位，金额和描述不能为空。",
    args_schema=ValidateInputSchema,
)